package am.fp.toolbars
{ 
  import fl.controls.Button;                    
  import flash.events.Event;
  
  import am.fp.Toolbar;
  import am.fp.FPDispatcher;
  import am.fp.events.SidePaneEvent;
  
  /**
   * Toolbar containing the print button.
   */
  public class Tool extends Toolbar
  { 
    private var m_btnPrint: Button;
    
    public function Tool()
    {
      m_btnPrint = addButton("PrintIcon");
      m_btnPrint.toggle = true;
      m_btnPrint.selected = false;
      
      m_btnPrint.addEventListener(Event.CHANGE, onPrint, false, 0, true);
      FPDispatcher.instance.addEventListener(SidePaneEvent.CHANGE, onSidePaneChange, false, 0, true);
    }
    
    protected function onPrint(e: Event): void
    {
      FPDispatcher.instance.dispatchEvent(new SidePaneEvent(SidePaneEvent.TOGGLE, SidePaneEvent.PANE_PRINT));
    }
    
    /**
     * Sync print toggle button state.
     */
    protected function onSidePaneChange(e: SidePaneEvent): void
    {
      if (e.paneId == SidePaneEvent.PANE_PRINT)
        m_btnPrint.selected = e.visible;
    }
  }
}
